package com.xinfu.newproject.adapter.paycost_adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xinfu.newproject.R;


/**
 *
 */
public class InvoiceAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private int isRemove;
    private EditText editText;
    private EditTextLisener editTextLisener;

    public InvoiceAdapter(EditTextLisener editTextLisener) {
        super(R.layout.recycler_invoice, null);
        this.editTextLisener = editTextLisener;
    }

    public void removeText(int isRemove) {
        this.isRemove = isRemove;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        editText = helper.getView(R.id.recycler_invoice_et);
        editText.setHint(item);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String nowText = editable.toString();
                if (nowText.length() > 0) {
                    editTextLisener.editLisener(helper.getPosition(), nowText);
                } else {
                    editTextLisener.editLisener(helper.getPosition(), null);
                }
            }
        });
        if (isRemove == 1) {
            editText.getText().clear();
        }
    }


    public interface EditTextLisener {
        void editLisener(int postion, String text);
    }
}
